/**
 * 获取树形结构深度
 * @param {*} treeData 
 * @returns 
 */
 export function getMaxFloor (treeData) {
    // eslint-disable-next-line no-unused-vars
    let floor = 0
    // eslint-disable-next-line no-unused-vars
    let v = this
    let max = 0
    function each (data, floor) {
        data.forEach(e => {
            e.floor = floor
            if (floor > max) {
                max = floor
            }
            if (e.children && e.children.length > 0) {
                each(e.children, floor + 1)
            }
        })
    }
    each(treeData,1)
    return max
}

/**
 * 过滤父级,只取子级(以key+children为标识)
 * @param data
 * @returns
 */
export const deepChildByKey = (data) => {
    let res = [];
    const dg = (data) => {
      data.forEach((item) => {
        if (item.children && item.children.length > 0) {
          dg(item.children);
        } else {
          res.push(item.key);
        }
      });
    };
    dg(data);
    return res;
  };
  
  /**
   * 过滤父级,只取子级(以id+children为标识)
   * @param data
   * @returns
   */
  export const deepChildById = (data) => {
    let res = [];
    const dg = (data) => {
      data.forEach((item) => {
        if (item.children && item.children.length > 0) {
          dg(item.children);
        } else {
          res.push(item.id);
        }
      });
    };
    dg(data);
    return res;
  };
  
  /**
   * 取出树形结构中的所有id
   * @param data
   * @returns
   */
  export const deepListById = (data) => {
    let res = [];
    const dg = (data) => {
      data.forEach((item) => {
        res.push(item.id);
        if (item.children && item.children.length > 0) {
          dg(item.children);
        }
      });
    };
    dg(data);
    return res;
  };
  
  /**
   * 取出树形结构中的所有key
   * @param data
   * @returns
   */
  export const deepListByKey = (data) => {
    let res = [];
    const dg = (data) => {
      data.forEach((item) => {
        res.push(item.key);
        if (item.children && item.children.length > 0) {
          dg(item.children);
        }
      });
    };
    dg(data);
    return res;
  };
  